#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
class Solution
{
public:
    int rearrangeCharacters(string s, string target)
    {
        int res = 200;
        unordered_map<int, int> dis, dit;
        for (auto &ch : s)
        {
            dis[ch - 'a']++;
        }
        for (auto &ch : target)
        {
            dit[ch - 'a']++;
        }
        for (int i = 0; i < 26; ++i)
        {
            if (dit[i] == 0)
                continue;
            res = min(res, dis[i] / dit[i]);
        }
        return res;
    }
};
int main()
{
    Solution s;
    string str = "ilovecodingonleetcode", target = "code";
    cout << s.rearrangeCharacters(str, target) << endl;
    system("pause");
    return 0;
}
